//
//  GHKuSuJiuYi.m
//  guahao
//
//  Created by osx on 16/9/25.
//  Copyright © 2016年 osx. All rights reserved.
//

#import "GHKuSuJiuYi.h"
#import "UIButton+Extension.h"
#import "UserInfoModel.h"
#import "Masonry.h"
#import "UIView+Extension.h"
#import "GHDocterController.h"
#import "GHNetWorkTools.h"
#import "DoctorViewControllerTableViewController.h"


@interface GHKuSuJiuYi()

@property (nonatomic, strong) UIButton *userInfo;
@property (nonatomic, strong) UIView *jiBingLeiXing;
@property (nonatomic, strong) UIView *jiBingXiFen;
@property (nonatomic, strong) UIView *isQueZhen;
@property (nonatomic, strong) UIView *isZhiLiao;
@property (nonatomic, strong) UIButton *jiuZhenShenQing;
@property (nonatomic ,assign) NSInteger ischoosejibingleixing;
@property (nonatomic ,assign) NSInteger ischoosejibingxifen;
@property (nonatomic ,copy) NSString *buttomName;
@property (nonatomic ,copy) NSString *buttomName2;

@end


static NSInteger buttonTag = 1;
static NSString *JBLX = @"疾病类型";
static NSString *JBXF = @"疾病细分";
static NSString *QZ = @"请选择是否确诊：";
static NSString *BFZZ = @"请选择并发症状";

@implementation GHKuSuJiuYi

-(NSString *)buttomName{

    if (!_buttomName) {
        _buttomName = @"疾病类型";
    }
    return _buttomName;
}
-(NSString *)buttomName2{
    
    if (!_buttomName2) {
        _buttomName2 = @"疾病细分";
    }
    return _buttomName2;
}

-(void)clickJiBingLeiXing:(UIButton*)bt{
    
    GHDocterController *vc = [[GHDocterController alloc] init];
    NSLog(@"%@ -----clickJiBingLeiXing",bt.titleLabel.text);
    if ([bt.titleLabel.text isEqualToString:@"疾病类型"]) {
        vc.title = JBLX;
        vc.array = [NSArray arrayWithObjects:@"肿瘤",@"心血管",@"神经科",@"血液科",@"骨科", nil];
    }else if ([bt.titleLabel.text isEqualToString:@"疾病细分"]){
        vc.title = JBXF;
        vc.array = [NSArray arrayWithObjects:@"肿瘤",@"心血管",@"神经科",@"血液科",@"骨科",@"dsfsdf", nil];
        
    }if ([bt.titleLabel.text isEqualToString:QZ]){
        vc.title = QZ;
        vc.array = [NSArray arrayWithObjects:@"已经确诊",@"尚未确诊", nil];
        
    }if ([bt.titleLabel.text isEqualToString:BFZZ]){
        vc.title = BFZZ;
        vc.array = [NSArray arrayWithObjects:@"恶心",@"呕吐",@"头晕",@"失眠", nil];
        
    }


    [self.navigationController pushViewController:vc animated:YES];
}

-(void)setButtonTitleNoti:(NSNotification*)noti{
   

    NSDictionary *dict = noti.userInfo;
    NSString *namestr =[dict valueForKey:@"name"];
    //int name = [namestr intValue];
    NSString *title = [dict valueForKey:@"title"];
    NSLog(@"setButtonTitleNoti------%@---%@",namestr,title);
    
    if ([namestr isEqualToString:JBLX] ) {
        UIButton *bt = [self.jiBingLeiXing viewWithTag:buttonTag];
        bt.titleLabel.text = title;
        //self.buttomName = title;
        
    }else if([namestr isEqualToString:JBXF]){
        UIButton *bt = [self.jiBingXiFen viewWithTag:buttonTag];
        bt.titleLabel.text = title;
    }else if([namestr isEqualToString:QZ]){
        UIButton *bt = [self.isQueZhen viewWithTag:buttonTag];
        bt.titleLabel.text = title;
    }else if([namestr isEqualToString:BFZZ]){
        UIButton *bt = [self.isZhiLiao viewWithTag:buttonTag];
        bt.titleLabel.text = title;
    }

}


-(void)viewDidLoad{

    [self.view setBackgroundColor:[UIColor whiteColor]];
   // [UIColor grayColor];
    
    self.title = @"快速就医";
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setButtonTitleNoti:) name:@"setButtonTitleName" object:nil];

    [self setUI];


}
-(void)setUI{
    
    CGFloat GHMarginView = 20;
    CGFloat GHNAheigh = 55;
    CGFloat GHHeight = 30;
    
    [self.view addSubview:self.userInfo];
    [self.view addSubview:self.jiBingLeiXing];
    [self.view addSubview:self.jiBingXiFen];
    [self.view addSubview:self.isQueZhen];
    [self.view addSubview:self.isZhiLiao];
    [self.view addSubview:self.jiuZhenShenQing];
    
    
    [self.userInfo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).with.offset(GHNAheigh+GHMarginView);
        make.left.equalTo(self.view).with.offset(GHMarginView);
        make.right.equalTo(self.view).with.offset(-GHMarginView);
        make.height.equalTo(@(GHHeight));
        
    }];
    
    [self.jiBingLeiXing mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.userInfo.mas_bottom).with.offset(GHMarginView);
        make.left.equalTo(self.userInfo.mas_left);
        make.right.equalTo(self.userInfo.mas_right);
        make.height.equalTo(self.userInfo.mas_height);
    }];
    // NSLog(@"%@",self.view.subviews);
    [self.jiBingXiFen mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.equalTo(self.jiBingLeiXing.mas_bottom).with.offset(GHMarginView);
        make.left.equalTo(self.userInfo.mas_left);
        make.right.equalTo(self.userInfo.mas_right);
        make.height.equalTo(self.userInfo.mas_height);
    }];
    [self.isQueZhen mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.jiBingXiFen.mas_bottom).with.offset(GHMarginView);
        make.left.equalTo(self.userInfo.mas_left);
        make.right.equalTo(self.userInfo.mas_right);
        make.height.equalTo(self.userInfo.mas_height);
    }];
    [self.isZhiLiao mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.isQueZhen.mas_bottom).with.offset(GHMarginView);
        make.left.equalTo(self.userInfo.mas_left);
        make.right.equalTo(self.userInfo.mas_right);
        make.height.equalTo(self.userInfo.mas_height);
    }];
    [self.jiuZhenShenQing mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view.mas_bottom).with.offset(-2*GHMarginView);
        make.left.equalTo(self.userInfo.mas_left);
        make.right.equalTo(self.userInfo.mas_right);
        make.height.equalTo(@(50));
    }];
    NSLog(@"%@",self.view.subviews);
}
-(UIView*)getBaseViewTitle:(NSString*)title imageName:(NSString*)imageName{
    
    UIView *view = [[UIView alloc] init];

    [view setBackgroundColor:[UIColor redColor]];
    
    //@"疾病类型"
    UIButton *bt = [UIButton initWithTitle:title fontsize:15 color:[UIColor grayColor]];
    [bt setBackgroundColor:[UIColor yellowColor]];
    bt.titleLabel.textAlignment = NSTextAlignmentLeft;
    bt.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    bt.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);
    bt.tag = buttonTag;
    [bt addTarget:self action:@selector(clickJiBingLeiXing:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:bt];
    
    UIView *placeview = [[UIView alloc] init];
    [view addSubview:placeview];
    
    
    //@"illness_button_input_blue.png"
    UIImageView *ima = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
    // UIButton *ima = [UIButton initWithTitle:@"" backImagename:@"illness_button_input_blue"];
    // [ima setBackgroundColor:[UIColor blueColor]];
    [ima sizeToFit];
    [view addSubview:ima];
    
    [bt mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.equalTo(view);
        make.width.equalTo(@(300));
    }];
    [placeview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.equalTo(view);
        make.left.equalTo(bt.mas_right);
    }];
    
    [ima mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(placeview);
    }];


    return view;
}
-(UIButton *)userInfo{

    if (!_userInfo) {
       // NSString *usernameid = [NSString stringWithFormat:@"%@   %@",[UserInfoModel shareUserInfoModel].username ,[UserInfoModel shareUserInfoModel].sex];
        NSString *usernameid = @"请选择";
        _userInfo = [UIButton initWithTitle:usernameid fontsize:15 color:[UIColor blackColor]];
    }
    
    return _userInfo;
}
-(UIView *)jiBingLeiXing{

    if (!_jiBingLeiXing) {
        
        _jiBingLeiXing = [self getBaseViewTitle:self.buttomName imageName:@"illness_button_input_blue.png"];
        
       
    }

    return _jiBingLeiXing;
}

-(UIView *)jiBingXiFen{
    
    if (!_jiBingXiFen) {
        NSLog(self.buttomName2);
        
        _jiBingXiFen = [self getBaseViewTitle:self.buttomName2 imageName:@"illness_button_input_blue.png"];
        
    }
    
    return _jiBingXiFen;
}
-(UIView *)isQueZhen{

    if (!_isQueZhen) {
        _isQueZhen = [self getBaseViewTitle:@"请选择是否确诊：" imageName:@"illness_button_input_blue.png"];
    }
    return _isQueZhen;
}
-(UIView *)isZhiLiao{

    if (!_isZhiLiao) {
        _isZhiLiao = [self getBaseViewTitle:@"请选择并发症状" imageName:@"illness_button_input_blue.png"];
    }
    return _isZhiLiao;
}
-(UIButton *)jiuZhenShenQing{

    if (!_jiuZhenShenQing) {
        _jiuZhenShenQing = [UIButton initWithTitle:@"就诊申请" fontsize:22 color:[UIColor blackColor]];
        [_jiuZhenShenQing setBackgroundColor:[UIColor grayColor]];
        [_jiuZhenShenQing addTarget:self action:@selector(clickjiuZhenShenQing) forControlEvents:UIControlEventTouchUpInside];
    }
    return _jiuZhenShenQing;
}
-(void)clickjiuZhenShenQing{
    
    NSLog(@"clickjiuZhenShenQing----");
    NSString *urlstr = @"doctor";
    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@"",@"", nil];
    
    
    
    NSLog(@"%@",urlstr);
    [[GHNetWorkTools sharedTools] requestDataWith:GET urlString:urlstr parameters:dict finishedBlock:^(id result, NSError *error) {
        NSLog(@"%@",result);
        
        DoctorViewControllerTableViewController* need=[[DoctorViewControllerTableViewController alloc]init];
        
        need.models = [result valueForKey:@"Doctor"];
        need.title = @"匹配列表";
        //设置返回按钮样式
        self.navigationItem.backBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
        [self.navigationController pushViewController:need animated:YES];
        
        
        
    }];

}
@end
